
#include "../ui.h"
#include "../app_includes.h"

#define WAVE_POINT_NUM     (420)

typedef struct
{
    lv_obj_t *panel;
    lv_obj_t *name;
    lv_obj_t *value;
    lv_obj_t *set;
    lv_obj_t *set_value;
    lv_obj_t *duty;
}lv_heater_panel_t;

typedef struct
{
    lv_obj_t *panel;
    lv_obj_t *panel_separate[2];
    lv_heater_panel_t group[3];

}lv_heater_group_t;

typedef struct
{
    uint8_t id;
    uint16_t *src_value;
    uint16_t shortcut[4];
    char *name;
}lv_set_value_t;

typedef struct
{
    uint16_t amp; //放大倍数
    uint16_t max; //最大值
}lv_meter_para_t;

static lv_obj_t *ui_screen;
static lv_obj_t *ui_PanelSet;
static lv_obj_t *ui_BtnGun;
static lv_obj_t *ui_BtnPlate;
static lv_obj_t *ui_BtnSolder;
static lv_obj_t *ui_Chart;
static lv_chart_cursor_t *ui_Cursor;
static lv_obj_t *ui_DropdownChart;

static lv_obj_t *ui_BtnPower;
static lv_obj_t *ui_LabelPowerStart;
static lv_obj_t *ui_Panel;
static lv_obj_t *ui_LabelPowerV;
static lv_obj_t *ui_LabelPowerI;
static lv_obj_t *ui_LabelPowerP;
static lv_obj_t *ui_BtnSetPowerI;
static lv_obj_t *ui_LabelPowerISet;
static lv_obj_t *ui_BtnSetPowerV;
static lv_obj_t *ui_LabelPowerVSet;
static lv_obj_t *ui_BtnCCMode;
static lv_obj_t *ui_LabelCCMode;

static lv_obj_t *ui_PanelSetValue;
static lv_obj_t *ui_TextSetValue;
static lv_obj_t *ui_LabelSetValueName;
static lv_obj_t *ui_keyboard;
static lv_obj_t *ui_ArcGunFan;
static lv_obj_t *ui_LabelGunFan;
static lv_obj_t *ui_BtnShortcut;

static lv_obj_t *ui_TabView;
static lv_obj_t *ui_TabPage1;
static lv_obj_t *ui_TabPage2;

static lv_obj_t *ui_LabelSolderType;
static lv_obj_t *ui_LabelSolder;
static lv_obj_t *ui_PanelMessage;

static lv_timer_t *lv_timer;
static lv_chart_series_t *ui_series_temp;
static lv_chart_series_t *ui_series_pwm;

static lv_coord_t wave[WAVE_POINT_NUM];
static uint16_t has_show_num = 0;

static char btnShortcutLabel[5][8] = {"111","222","333","444","",};
static char *btnShortcutMap[] = {btnShortcutLabel[0],btnShortcutLabel[1],btnShortcutLabel[2],btnShortcutLabel[3],btnShortcutLabel[4],};
static char *solder_type[] = {"未连接", "T12", "C245", "C210", "未知"};
    
static lv_meter_para_t meter_para_group[] = {
    {100, 3000}, //电源电压
    {100, 1000}, //电源电流
    {10, 3000},  //电源功率
    {100, 8000}, //环境温度
    {10, 5000},  //烙铁温度
    {100, 1000}, //烙铁电流
    {10, 3000},  //烙铁功率
    {10, 5000},  //风枪温度
    {10, 5000},  //加热台温度
    {100, 5000}, //数控电源电压
    {100, 1000}, //数控电源电流
};

static uint8_t set_value_select = 0;
static lv_set_value_t set_value_group[] = {
    {0, &app_slave_dev_mht.para.run.solder_temp, {100,200,380,420,}, "烙铁温度[℃]"},
    {1, &app_slave_dev_mht.para.run.gun_temp, {100,200,380,420,}, "风枪温度[℃]"},
    {2, &app_slave_dev_mht.para.run.plate_temp, {50,100,200,300,}, "加热台温度[℃]"},
    {3, &app_slave_dev_mht.para.run.power_set_u, {3300,5000,12000,24000,}, "输出电压[mV]"},
    {4, &app_slave_dev_mht.para.run.power_set_i, {1000,2000,3000,5000,}, "输出电流[mA]"},
};

static void data_refresh(lv_timer_t *timer);
static void wave_refresh(void);

static lv_heater_group_t heater;
static void lv_heater_group_init(lv_heater_group_t *heater, lv_obj_t *parent);
static void btn_solder_event_cb(lv_event_t * e);
static void btn_gun_event_cb(lv_event_t * e);
static void btn_plate_event_cb(lv_event_t * e);
static void btn_power_event_cb(lv_event_t * e);
static void shortcut_event_cb(lv_event_t * e);
static void set_value_event_cb(lv_event_t * e);
static void dropdownChart_event_cb(lv_event_t * e);
static void ta_event_cb(lv_event_t * e);


void lv_solder_close(void)
{
    lv_timer_del(lv_timer);
}

//app应用入口
lv_obj_t *lv_solder_open(void)
{
    lv_obj_t *t;
    ui_screen = lv_screen_create(ui_main_screen.desktop, LV_HOR_RES, LV_VER_RES);
    //ui_screen = ui_main_screen.desktop;

    ui_TabView = lv_tabview_create(ui_screen, LV_DIR_TOP, 0);
    lv_obj_set_height( ui_TabView, 260);
    lv_obj_set_width( ui_TabView, lv_pct(100));
    lv_obj_set_align( ui_TabView, LV_ALIGN_TOP_MID );
    lv_obj_clear_flag( ui_TabView, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_bg_color(ui_TabView, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_TabView, 255, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_TabPage1 = lv_tabview_add_tab(ui_TabView, "1");
    ui_TabPage2 = lv_tabview_add_tab(ui_TabView, "2");

    lv_heater_group_init(&heater, ui_TabPage1);

    ui_BtnSolder = lv_btn_create(ui_TabPage1);
    lv_obj_set_width( ui_BtnSolder, 120);
    lv_obj_set_height( ui_BtnSolder, 40);
    lv_obj_align_to( ui_BtnSolder, heater.panel, LV_ALIGN_OUT_BOTTOM_MID, -140, 20 );
    lv_obj_add_flag( ui_BtnSolder, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnSolder, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnSolder, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnSolder, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnSolder, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnSolder, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnSolder, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnSolder, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    /*lv_obj_set_style_bg_color(ui_BtnSolder, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnSolder, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnSolder, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnSolder, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnSolder, 2, LV_PART_MAIN| LV_STATE_CHECKED);*/

    t = lv_label_create(ui_BtnSolder);
    lv_obj_set_width( t, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( t, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( t, LV_ALIGN_CENTER );
    lv_label_set_text(t,"电烙铁");
    lv_obj_set_style_text_font(t, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnGun = lv_btn_create(ui_TabPage1);
    lv_obj_set_width( ui_BtnGun, 120);
    lv_obj_set_height( ui_BtnGun, 40);
    lv_obj_set_x( ui_BtnGun, 0 );
    lv_obj_set_y( ui_BtnGun, -40 );
    lv_obj_align_to( ui_BtnGun, heater.panel, LV_ALIGN_OUT_BOTTOM_MID, 0, 20 );
    lv_obj_add_flag( ui_BtnGun, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnGun, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnGun, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnGun, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnGun, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnGun, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnGun, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnGun, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    /*lv_obj_set_style_bg_color(ui_BtnGun, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnGun, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnGun, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnGun, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnGun, 2, LV_PART_MAIN| LV_STATE_CHECKED);*/

    t = lv_label_create(ui_BtnGun);
    lv_obj_set_width( t, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( t, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( t, LV_ALIGN_CENTER );
    lv_label_set_text(t,"热风枪");
    lv_obj_set_style_text_font(t, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);


    ui_BtnPlate = lv_btn_create(ui_TabPage1);
    lv_obj_set_width( ui_BtnPlate, 120);
    lv_obj_set_height( ui_BtnPlate, 40);
    lv_obj_align_to( ui_BtnPlate, heater.panel, LV_ALIGN_OUT_BOTTOM_MID, 140, 20 );
    lv_obj_add_flag( ui_BtnPlate, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnPlate, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnPlate, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnPlate, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnPlate, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnPlate, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnPlate, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnPlate, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    /*lv_obj_set_style_bg_color(ui_BtnPlate, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnPlate, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnPlate, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnPlate, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnPlate, 2, LV_PART_MAIN| LV_STATE_CHECKED);*/

    t = lv_label_create(ui_BtnPlate);
    lv_obj_set_width( t, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( t, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( t, LV_ALIGN_CENTER );
    lv_label_set_text(t,"加热台");
    lv_obj_set_style_text_font(t, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_Chart = lv_chart_create(ui_screen);
    lv_obj_set_width( ui_Chart, 460);
    lv_obj_set_height( ui_Chart, 220);
    lv_obj_set_align( ui_Chart, LV_ALIGN_BOTTOM_MID );
    lv_chart_set_type( ui_Chart, LV_CHART_TYPE_LINE);
    lv_chart_set_point_count(ui_Chart,WAVE_POINT_NUM);//图表上点的个数
    lv_chart_set_range(ui_Chart, LV_CHART_AXIS_PRIMARY_Y, 0, meter_para_group[0].max);
    lv_chart_set_div_line_count( ui_Chart, 7, 15);
    lv_chart_set_axis_tick( ui_Chart, LV_CHART_AXIS_PRIMARY_X, 8, 4, 0, 5, false, 50);
    lv_chart_set_axis_tick( ui_Chart, LV_CHART_AXIS_PRIMARY_Y, 8, 4, 7, 5, true, 50);
    lv_chart_set_axis_tick( ui_Chart, LV_CHART_AXIS_SECONDARY_Y, 10, 5, 0, 0, false, 25);
    ui_series_temp = lv_chart_add_series(ui_Chart, lv_color_hex(0x00ff00), LV_CHART_AXIS_PRIMARY_Y);
    lv_chart_set_ext_y_array(ui_Chart, ui_series_temp, wave);
    lv_obj_set_style_bg_color(ui_Chart, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_Chart, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_size(ui_Chart, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_Chart, 0, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_Cursor = lv_chart_add_cursor(ui_Chart, lv_color_hex(0xff0000), LV_DIR_HOR);
    lv_point_t point = {-1, 150};
    lv_chart_set_cursor_pos(ui_Chart, ui_Cursor, &point);
    
    ui_DropdownChart = lv_dropdown_create(ui_screen);
    lv_dropdown_set_options( ui_DropdownChart, "电源电压\n电源电流\n电源功率\n环境温度\n烙铁温度\n烙铁电流\n烙铁功率\n风枪温度\n加热台温度\n数控电源电压\n数控电源电流" );
    lv_obj_set_width( ui_DropdownChart, 120);
    lv_obj_set_height( ui_DropdownChart, LV_SIZE_CONTENT+10);   /// 1
    lv_obj_align_to( ui_DropdownChart, ui_Chart, LV_ALIGN_TOP_LEFT, 10, 10 );
    lv_obj_add_flag( ui_DropdownChart, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_set_style_text_font(ui_DropdownChart, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_DropdownChart, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_DropdownChart, 0, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_DropdownChart, 0, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_DropdownChart, &lv_font_montserrat_14, LV_PART_INDICATOR| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(lv_dropdown_get_list(ui_DropdownChart), &ui_font_FontChineseSmall,  LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_Panel = lv_obj_create(ui_TabPage2);
    lv_obj_set_width( ui_Panel, 246);
    lv_obj_set_height( ui_Panel, 180);
    lv_obj_set_align( ui_Panel, LV_ALIGN_LEFT_MID );
    lv_obj_clear_flag( ui_Panel, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_Panel, 20, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_Panel, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_Panel, 255, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_LabelPowerV = lv_label_create(ui_Panel);
    lv_obj_set_width( ui_LabelPowerV, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerV, LV_SIZE_CONTENT);   /// 1
    lv_obj_align( ui_LabelPowerV, LV_ALIGN_LEFT_MID, 5, -55 );
    lv_label_set_text(ui_LabelPowerV,"V 00.00");
    lv_obj_set_style_text_color(ui_LabelPowerV, lv_color_hex(0xDCE04B), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_opa(ui_LabelPowerV, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_LabelPowerV, &ui_font_FontNumber64, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_LabelPowerI = lv_label_create(ui_Panel);
    lv_obj_set_width( ui_LabelPowerI, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerI, LV_SIZE_CONTENT);   /// 1
    lv_obj_align( ui_LabelPowerI, LV_ALIGN_LEFT_MID, 5, 0 );
    lv_label_set_text(ui_LabelPowerI,"A 0.000");
    lv_obj_set_style_text_color(ui_LabelPowerI, lv_color_hex(0xA0CFCF), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_opa(ui_LabelPowerI, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_LabelPowerI, &ui_font_FontNumber64, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_LabelPowerP = lv_label_create(ui_Panel);
    lv_obj_set_width( ui_LabelPowerP, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerP, LV_SIZE_CONTENT);   /// 1
    lv_obj_align( ui_LabelPowerP, LV_ALIGN_LEFT_MID, 5, 55 );
    lv_label_set_text(ui_LabelPowerP,"P 120.0");
    lv_obj_set_style_text_color(ui_LabelPowerP, lv_color_hex(0x99DC48), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_opa(ui_LabelPowerP, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui_LabelPowerP, &ui_font_FontNumber64, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnSetPowerI = lv_btn_create(ui_TabPage2);
    lv_obj_set_width( ui_BtnSetPowerI, 160);
    lv_obj_set_height( ui_BtnSetPowerI, 40);
    lv_obj_align( ui_BtnSetPowerI, LV_ALIGN_RIGHT_MID, 0, 0 );
    lv_obj_add_flag( ui_BtnSetPowerI, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnSetPowerI, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnSetPowerI, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnSetPowerI, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnSetPowerI, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnSetPowerI, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnSetPowerI, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnSetPowerI, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnSetPowerI, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnSetPowerI, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnSetPowerI, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnSetPowerI, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnSetPowerI, 2, LV_PART_MAIN| LV_STATE_CHECKED);

    ui_LabelPowerISet = lv_label_create(ui_BtnSetPowerI);
    lv_obj_set_width( ui_LabelPowerISet, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerISet, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelPowerISet, LV_ALIGN_LEFT_MID );
    lv_label_set_text(ui_LabelPowerISet,"SET A: 0.500");
    lv_obj_set_style_text_font(ui_LabelPowerISet, &ui_font_FontChinese, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnSetPowerV = lv_btn_create(ui_TabPage2);
    lv_obj_set_width( ui_BtnSetPowerV, 160);
    lv_obj_set_height( ui_BtnSetPowerV, 40);
    lv_obj_align( ui_BtnSetPowerV, LV_ALIGN_RIGHT_MID, 0, -55 );
    lv_obj_add_flag( ui_BtnSetPowerV, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnSetPowerV, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnSetPowerV, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnSetPowerV, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnSetPowerV, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnSetPowerV, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnSetPowerV, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnSetPowerV, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnSetPowerV, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnSetPowerV, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnSetPowerV, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnSetPowerV, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnSetPowerV, 2, LV_PART_MAIN| LV_STATE_CHECKED);

    ui_LabelPowerVSet = lv_label_create(ui_BtnSetPowerV);
    lv_obj_set_width( ui_LabelPowerVSet, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerVSet, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelPowerVSet, LV_ALIGN_LEFT_MID );
    lv_label_set_text(ui_LabelPowerVSet,"SET V: 20.00");
    lv_obj_set_style_text_font(ui_LabelPowerVSet, &ui_font_FontChinese, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnCCMode = lv_btn_create(ui_TabPage2);
    lv_obj_set_width( ui_BtnCCMode, 76);
    lv_obj_set_height( ui_BtnCCMode, 40);
    lv_obj_align( ui_BtnCCMode, LV_ALIGN_RIGHT_MID, -84, 55 );
    lv_obj_clear_flag( ui_BtnCCMode, LV_OBJ_FLAG_CHECKABLE | LV_OBJ_FLAG_CLICKABLE );   /// Flags
    lv_obj_add_flag( ui_BtnCCMode,  LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnCCMode, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnCCMode, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnCCMode, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnCCMode, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnCCMode, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnCCMode, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnCCMode, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnCCMode, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnCCMode, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnCCMode, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnCCMode, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnCCMode, 2, LV_PART_MAIN| LV_STATE_CHECKED);

    ui_LabelCCMode = lv_label_create(ui_BtnCCMode);
    lv_obj_set_width( ui_LabelCCMode, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelCCMode, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelCCMode, LV_ALIGN_CENTER );
    lv_label_set_text(ui_LabelCCMode,"CV");
    lv_obj_set_style_text_font(ui_LabelCCMode, &ui_font_FontChinese, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnPower = lv_btn_create(ui_TabPage2);
    lv_obj_set_width( ui_BtnPower, 76);
    lv_obj_set_height( ui_BtnPower, 40);
    lv_obj_align( ui_BtnPower, LV_ALIGN_RIGHT_MID, 0, 55 );
    lv_obj_add_flag( ui_BtnPower, LV_OBJ_FLAG_SCROLL_ON_FOCUS );   /// Flags
    lv_obj_clear_flag( ui_BtnPower, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_BtnPower, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_BtnPower, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(ui_BtnPower, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_color(ui_BtnPower, lv_color_hex(0x00B4B4), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_border_opa(ui_BtnPower, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui_BtnPower, 2, LV_PART_MAIN| LV_STATE_DEFAULT);
    /*lv_obj_set_style_bg_color(ui_BtnPower, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_bg_opa(ui_BtnPower, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_color(ui_BtnPower, lv_color_hex(0x3EF33A), LV_PART_MAIN | LV_STATE_CHECKED );
    lv_obj_set_style_border_opa(ui_BtnPower, 255, LV_PART_MAIN| LV_STATE_CHECKED);
    lv_obj_set_style_border_width(ui_BtnPower, 2, LV_PART_MAIN| LV_STATE_CHECKED);*/

    ui_LabelPowerStart = lv_label_create(ui_BtnPower);
    lv_obj_set_width( ui_LabelPowerStart, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelPowerStart, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelPowerStart, LV_ALIGN_CENTER );
    lv_label_set_text(ui_LabelPowerStart,"启动");
    lv_obj_set_style_text_font(ui_LabelPowerStart, &ui_font_FontChinese, LV_PART_MAIN| LV_STATE_DEFAULT);

    
    lv_obj_add_event_cb(ui_BtnSolder, btn_solder_event_cb, LV_EVENT_CLICKED, NULL);
    lv_obj_add_event_cb(ui_BtnPower, btn_power_event_cb, LV_EVENT_CLICKED, NULL);
    lv_obj_add_event_cb(ui_BtnGun, btn_gun_event_cb, LV_EVENT_CLICKED, NULL);
    lv_obj_add_event_cb(ui_BtnPlate, btn_plate_event_cb, LV_EVENT_CLICKED, NULL);

    //键盘设置参数
    ui_PanelSetValue = lv_obj_create(ui_screen);
    lv_obj_set_height( ui_PanelSetValue, 220);
    lv_obj_set_width( ui_PanelSetValue, lv_pct(100));
    lv_obj_set_align( ui_PanelSetValue, LV_ALIGN_BOTTOM_MID );
    lv_obj_add_flag(ui_PanelSetValue, LV_OBJ_FLAG_HIDDEN);
    lv_obj_clear_flag( ui_PanelSetValue, LV_OBJ_FLAG_SCROLLABLE );    /// Flags

    ui_ArcGunFan = lv_arc_create(ui_PanelSetValue);
    lv_obj_set_width( ui_ArcGunFan, 60);
    lv_obj_set_height( ui_ArcGunFan, 60);
    lv_obj_align( ui_ArcGunFan, LV_ALIGN_TOP_RIGHT, 0, 10);
    //lv_obj_set_style_arc_width(ui_ArcGunFan, 20, LV_PART_MAIN| LV_STATE_DEFAULT);
    //lv_obj_set_style_arc_width(ui_ArcGunFan, 20, LV_PART_INDICATOR| LV_STATE_DEFAULT);
    lv_obj_set_style_opa(ui_ArcGunFan, 0, LV_PART_KNOB| LV_STATE_DEFAULT);
    lv_arc_set_range(ui_ArcGunFan, 1, 5);


    ui_LabelGunFan = lv_label_create(ui_ArcGunFan);
    lv_obj_set_width( ui_LabelGunFan, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelGunFan, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelGunFan, LV_ALIGN_CENTER );
    lv_label_set_text(ui_LabelGunFan,"风枪");
    lv_obj_set_style_text_font(ui_LabelGunFan, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_BtnShortcut = lv_btnmatrix_create(ui_PanelSetValue);
    lv_obj_set_style_border_width(ui_BtnShortcut, 0, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_size(ui_BtnShortcut, 280, 80);
    lv_obj_align_to( ui_BtnShortcut, ui_ArcGunFan, LV_ALIGN_OUT_LEFT_MID, -5, 0);
    lv_btnmatrix_set_map(ui_BtnShortcut, (const char **)btnShortcutMap);

    ui_TextSetValue = lv_textarea_create(ui_PanelSetValue);
    lv_obj_set_width( ui_TextSetValue, 100);
    lv_obj_set_height( ui_TextSetValue, 40);
    lv_obj_align_to( ui_TextSetValue, ui_BtnShortcut, LV_ALIGN_OUT_LEFT_BOTTOM, 0, -10);
    lv_textarea_set_text(ui_TextSetValue,"300");
    lv_textarea_set_placeholder_text(ui_TextSetValue,"");
    lv_obj_set_style_bg_color(ui_TextSetValue, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_font(ui_TextSetValue, &lv_font_montserrat_22, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_TextSetValue, 255, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_LabelSetValueName = lv_label_create(ui_PanelSetValue);
    lv_obj_set_width( ui_LabelSetValueName, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelSetValueName, LV_SIZE_CONTENT);   /// 1
    lv_obj_align_to( ui_LabelSetValueName, ui_TextSetValue, LV_ALIGN_OUT_TOP_LEFT, 0, -5);
    lv_label_set_text(ui_LabelSetValueName,"烙铁温度");
    lv_obj_set_style_text_font(ui_LabelSetValueName, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);


    ui_keyboard = lv_keyboard_create(ui_PanelSetValue);
    lv_keyboard_set_mode(ui_keyboard,LV_KEYBOARD_MODE_NUMBER);
    lv_obj_set_height( ui_keyboard, 120);
    lv_obj_set_width( ui_keyboard, lv_pct(100));
    lv_obj_set_x( ui_keyboard, 0 );
    lv_obj_set_y( ui_keyboard, 0 );
    lv_obj_set_align( ui_keyboard, LV_ALIGN_BOTTOM_MID );

    lv_keyboard_set_textarea(ui_keyboard, ui_TextSetValue);
    lv_obj_add_event_cb(ui_TextSetValue, ta_event_cb, LV_EVENT_ALL, ui_keyboard);
    
    ui_PanelMessage = lv_obj_create(ui_screen);
    lv_obj_set_width( ui_PanelMessage, 200);
    lv_obj_set_height( ui_PanelMessage, 30);
    lv_obj_set_align( ui_PanelMessage, LV_ALIGN_TOP_MID );
    lv_obj_clear_flag( ui_PanelMessage, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(ui_PanelMessage, 10, LV_PART_MAIN| LV_STATE_DEFAULT);

    ui_LabelSolder = lv_label_create(ui_PanelMessage);
    lv_obj_set_width( ui_LabelSolder, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelSolder, LV_SIZE_CONTENT);   /// 1
    lv_obj_set_align( ui_LabelSolder, LV_ALIGN_LEFT_MID );
    lv_label_set_text(ui_LabelSolder,LV_SYMBOL_EDIT);

    ui_LabelSolderType = lv_label_create(ui_PanelMessage);
    lv_obj_set_width( ui_LabelSolderType, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( ui_LabelSolderType, LV_SIZE_CONTENT);   /// 1
    lv_obj_align_to( ui_LabelSolderType, ui_LabelSolder, LV_ALIGN_OUT_RIGHT_MID, 10, 0 );
    lv_label_set_text(ui_LabelSolderType, solder_type[0]);
    lv_obj_set_style_text_font(ui_LabelSolderType, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);
    

    lv_obj_add_event_cb(heater.group[0].panel, set_value_event_cb, LV_EVENT_CLICKED,  &set_value_group[0]);
    lv_obj_add_event_cb(heater.group[1].panel, set_value_event_cb, LV_EVENT_CLICKED,  &set_value_group[1]);
    lv_obj_add_event_cb(heater.group[2].panel, set_value_event_cb, LV_EVENT_CLICKED,  &set_value_group[2]);
    lv_obj_add_event_cb(ui_BtnSetPowerV, set_value_event_cb, LV_EVENT_CLICKED, &set_value_group[3]);
    lv_obj_add_event_cb(ui_BtnSetPowerI, set_value_event_cb, LV_EVENT_CLICKED, &set_value_group[4]);
    lv_obj_add_event_cb(ui_BtnShortcut, shortcut_event_cb, LV_EVENT_VALUE_CHANGED,NULL);  
    lv_obj_add_event_cb(ui_DropdownChart, dropdownChart_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    
    lv_timer = lv_timer_create(data_refresh, 40, NULL);

    return ui_screen;
}

void cursor_refresh(void) 
{
    lv_point_t point = {-1,0};
    uint8_t index = lv_dropdown_get_selected(ui_DropdownChart);
    int16_t set_value = meter_para_group[index].max;
    
    if(index==4)
        set_value = app_slave_dev_mht.para.run.solder_temp*meter_para_group[index].amp;
    else if(index==7)
        set_value = app_slave_dev_mht.para.run.gun_temp*meter_para_group[index].amp;
    else if(index==8)
        set_value = app_slave_dev_mht.para.run.plate_temp*meter_para_group[index].amp;
    
    wave[0] = set_value;
    lv_chart_refresh(ui_Chart);
    lv_chart_get_point_pos_by_id(ui_Chart, ui_series_temp, 0, &point);
    point.x = -1;
    lv_chart_set_cursor_pos(ui_Chart, ui_Cursor, &point); 
    lv_chart_set_all_value(ui_Chart, ui_series_temp, -1);
    has_show_num = 0;
}

void para_refresh(void)
{
    uint32_t color[] = {0x00B4B4, 0xC31111, 0x3EF33A, };
    char str[32];
    EventBits_t event = xEventGroupWaitBits(hmt_device_event,khmtEvent_ParaChange,pdTRUE,pdFALSE,0);
    if(event&khmtEvent_StoreParaChange) {
        ;
    }
    if(event&khmtEvent_RunParaChange) {
        //输出电源
        strcpy(str, "SET A:");
        uint_to_str(str+strlen(str), app_slave_dev_mht.para.run.power_set_i, 3, 5, NULL);
        lv_label_set_text(ui_LabelPowerISet, str);
        strcpy(str, "SET V:");
        uint_to_str(str+strlen(str), app_slave_dev_mht.para.run.power_set_u/10, 2, 5, NULL);
        lv_label_set_text(ui_LabelPowerVSet, str);
        //设置温度
        strcpy(str, "/");
        uint_to_str(&str[1], app_slave_dev_mht.para.run.solder_temp, 0, 3, NULL);
        lv_label_set_text(heater.group[0].set_value, str);
        uint_to_str(&str[1], app_slave_dev_mht.para.run.gun_temp, 0, 3, NULL);
        lv_label_set_text(heater.group[1].set_value, str);
        uint_to_str(&str[1], app_slave_dev_mht.para.run.plate_temp, 0, 3, NULL);
        lv_label_set_text(heater.group[2].set_value, str);
        //波形参考线 
        cursor_refresh();
    }
    if(event&khmtEvent_StatusParaChange) {
        lv_label_set_text(ui_LabelSolderType, solder_type[app_slave_dev_mht.para.status.solder_type]);
        lv_obj_set_style_border_color(ui_BtnSolder, lv_color_hex(color[app_slave_dev_mht.para.status.solder_work]), LV_PART_MAIN | LV_STATE_DEFAULT );
        lv_obj_set_style_border_color(ui_BtnGun, lv_color_hex(color[app_slave_dev_mht.para.status.gun_work]), LV_PART_MAIN | LV_STATE_DEFAULT );
        lv_obj_set_style_border_color(ui_BtnPlate, lv_color_hex(color[app_slave_dev_mht.para.status.plate_work]), LV_PART_MAIN | LV_STATE_DEFAULT );
        lv_obj_set_style_border_color(ui_BtnPower, lv_color_hex(color[app_slave_dev_mht.para.status.power_work]), LV_PART_MAIN | LV_STATE_DEFAULT );
    }
}

void data_refresh(lv_timer_t *timer)
{
    static uint8_t cnt = 0;
    char value_str[32];
    cnt++;
    if(cnt==25) { //1S更新一次
        cnt = 0;
        //焊台温度
        if(app_slave_dev_mht.meter[kMHT_MeterSolderTemp].valid)
            uint_to_str(value_str, (uint32_t)app_slave_dev_mht.meter[kMHT_MeterSolderTemp].value, 0, 3, NULL);  
        else
            strcpy(value_str, "---");
        lv_label_set_text(heater.group[0].value,value_str);
        //风枪温度
        if(app_slave_dev_mht.meter[kMHT_MeterGunTemp].valid)
            uint_to_str(value_str, (uint32_t)app_slave_dev_mht.meter[kMHT_MeterGunTemp].value, 0, 3, NULL);  
        else
            strcpy(value_str, "---");  
        lv_label_set_text(heater.group[1].value,value_str);
        //加热台温度
        if(app_slave_dev_mht.meter[kMHT_MeterPlateTemp].valid)
            uint_to_str(value_str, (uint32_t)app_slave_dev_mht.meter[kMHT_MeterPlateTemp].value, 0, 3, NULL);   
        else
            strcpy(value_str, "---");   
        lv_label_set_text(heater.group[2].value,value_str);
        
        //电源电压电流
        strcpy(value_str, "V ");
        float_to_str(value_str+strlen(value_str), app_slave_dev_mht.meter[kMHT_MeterPowerOutV].value, 2, 5, NULL);   
        lv_label_set_text(ui_LabelPowerV,value_str);
        strcpy(value_str, "A ");
        float_to_str(value_str+strlen(value_str), app_slave_dev_mht.meter[kMHT_MeterPowerOutI].value, 3, 5, NULL);   
        lv_label_set_text(ui_LabelPowerI,value_str);
        strcpy(value_str, "P ");
        float_to_str(value_str+strlen(value_str), app_slave_dev_mht.meter[kMHT_MeterPowerOutV].value*app_slave_dev_mht.meter[kMHT_MeterPowerOutI].value, 1, 5, NULL);   
        lv_label_set_text(ui_LabelPowerP,value_str);
    }
    para_refresh(); //更新参数
    wave_refresh(); //更新波形
    
}

void lv_heater_panel_init(lv_heater_panel_t *panel, lv_obj_t *parent, char *name)
{
    panel->panel = lv_obj_create(parent);
    lv_obj_set_width( panel->panel, 120);
    lv_obj_set_height( panel->panel, 60);
    lv_obj_clear_flag( panel->panel, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_bg_color(panel->panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(panel->panel, 0, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(panel->panel, 0, LV_PART_MAIN| LV_STATE_DEFAULT);

    panel->name = lv_label_create(panel->panel);
    lv_obj_set_width( panel->name, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( panel->name, LV_SIZE_CONTENT);   /// 1
    lv_obj_align( panel->name, LV_ALIGN_TOP_LEFT, 0, 0 );
    lv_label_set_text(panel->name, name);
    lv_obj_set_style_text_color(panel->name, lv_color_hex(0xC0C0C0), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_opa(panel->name, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(panel->name, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);

    panel->value = lv_label_create(panel->panel);
    lv_obj_set_width( panel->value, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( panel->value, LV_SIZE_CONTENT);   /// 1
    lv_obj_align_to( panel->value, panel->name, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
    lv_label_set_text(panel->value,"350");
    lv_obj_set_style_text_font(panel->value, &ui_font_FontChinese, LV_PART_MAIN| LV_STATE_DEFAULT);

    panel->set_value = lv_label_create(panel->panel);
    lv_obj_set_width( panel->set_value, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( panel->set_value, LV_SIZE_CONTENT);   /// 1
    lv_obj_align_to( panel->set_value, panel->value, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
    lv_label_set_text(panel->set_value,"/350");
    lv_obj_set_style_text_font(panel->set_value, &ui_font_FontChineseSmall, LV_PART_MAIN| LV_STATE_DEFAULT);

    panel->set = lv_label_create(panel->panel);
    lv_obj_set_width( panel->set, LV_SIZE_CONTENT);  /// 1
    lv_obj_set_height( panel->set, LV_SIZE_CONTENT);   /// 1
    lv_obj_align_to( panel->set, panel->name, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
    lv_label_set_text(panel->set," SET ");
    lv_obj_set_style_text_color(panel->set, lv_color_hex(0x00FF00), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_text_opa(panel->set, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_radius(panel->set, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(panel->set, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(panel->set, 255, LV_PART_MAIN| LV_STATE_DEFAULT);


    panel->duty = lv_bar_create(panel->panel);
    lv_obj_set_width( panel->duty, 8);
    lv_obj_set_height( panel->duty, 40);
    lv_obj_set_align( panel->duty, LV_ALIGN_RIGHT_MID );
    lv_bar_set_value(panel->duty,50,LV_ANIM_OFF);
}

void lv_heater_group_init(lv_heater_group_t *heater, lv_obj_t *parent)
{
    heater->panel = lv_obj_create(parent);
    lv_obj_set_size( heater->panel, 420, 80);
    lv_obj_align( heater->panel, LV_ALIGN_TOP_MID, 0, 50);
    lv_obj_clear_flag( heater->panel, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
    lv_obj_set_style_radius(heater->panel, 10, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(heater->panel, lv_color_hex(0x191D26), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(heater->panel, 255, LV_PART_MAIN| LV_STATE_DEFAULT);

    lv_heater_panel_init(&heater->group[0], heater->panel, "电烙铁");
    lv_obj_align(heater->group[0].panel, LV_ALIGN_CENTER, -140, 0);
    lv_heater_panel_init(&heater->group[1], heater->panel, "热风枪");
    lv_obj_align(heater->group[1].panel, LV_ALIGN_CENTER, 0, 0);
    lv_heater_panel_init(&heater->group[2], heater->panel, "加热台");
    lv_obj_align(heater->group[2].panel, LV_ALIGN_CENTER, 140, 0);

    heater->panel_separate[0] = lv_obj_create(heater->panel);
    lv_obj_set_width( heater->panel_separate[0], 2);
    lv_obj_set_height( heater->panel_separate[0], 50);
    lv_obj_align( heater->panel_separate[0], LV_ALIGN_CENTER, -70, 0);
    lv_obj_clear_flag( heater->panel_separate[0], LV_OBJ_FLAG_SCROLLABLE);    /// Flags
    lv_obj_set_style_bg_color(heater->panel_separate[0], lv_color_hex(0x3A3F4B), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(heater->panel_separate[0], 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(heater->panel_separate[0], 0, LV_PART_MAIN| LV_STATE_DEFAULT);
    heater->panel_separate[1] = lv_obj_create(heater->panel);
    lv_obj_set_width( heater->panel_separate[1], 2);
    lv_obj_set_height( heater->panel_separate[1], 50);
    lv_obj_align( heater->panel_separate[1], LV_ALIGN_CENTER, 70, 0);
    lv_obj_clear_flag( heater->panel_separate[1], LV_OBJ_FLAG_SCROLLABLE);    /// Flags
    lv_obj_set_style_bg_color(heater->panel_separate[1], lv_color_hex(0x3A3F4B), LV_PART_MAIN | LV_STATE_DEFAULT );
    lv_obj_set_style_bg_opa(heater->panel_separate[1], 255, LV_PART_MAIN| LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(heater->panel_separate[1], 0, LV_PART_MAIN| LV_STATE_DEFAULT);
}

static void send_write_para_cmd(void)
{
    uint8_t status = APPLY_STATUS_WRITE_PARA;
    app_slave_dev_mht.write_para_flag = ApplyParaRun;
    xQueueOverwrite(hmt_device_cmd_queue, &status);
}

static void btn_solder_event_cb(lv_event_t * e)
{
    app_slave_dev_mht.para.run.solder_enable = !app_slave_dev_mht.para.run.solder_enable;
    send_write_para_cmd();
}

static void btn_gun_event_cb(lv_event_t * e)
{
    app_slave_dev_mht.para.run.gun_enable = !app_slave_dev_mht.para.run.gun_enable;
    send_write_para_cmd();
}

static void btn_plate_event_cb(lv_event_t * e)
{
    app_slave_dev_mht.para.run.plate_enable = !app_slave_dev_mht.para.run.plate_enable;
    send_write_para_cmd();
}

static void btn_power_event_cb(lv_event_t * e)
{
    app_slave_dev_mht.para.run.power_enable = !app_slave_dev_mht.para.run.power_enable;
    send_write_para_cmd();
}
static void ta_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * ta = lv_event_get_target(e);
    lv_obj_t * kb = lv_event_get_user_data(e);
    if(code == LV_EVENT_READY || code == LV_EVENT_CANCEL){
        lv_obj_add_flag(ui_PanelSetValue, LV_OBJ_FLAG_HIDDEN);
    }
    if(code == LV_EVENT_READY) {
        //新值赋给对应参数
        *set_value_group[set_value_select].src_value = str_to_uint(lv_textarea_get_text(ui_TextSetValue));
        app_slave_dev_mht.para.run.gun_fan_gear = lv_arc_get_value(ui_ArcGunFan);
        send_write_para_cmd();
    }
}

static void set_value_event_cb(lv_event_t * e)
{
    uint8_t i;
    char str[16] = "200";
    lv_set_value_t *set = lv_event_get_user_data(e);

    //风枪挡位
    lv_arc_set_value(ui_ArcGunFan, app_slave_dev_mht.para.run.gun_fan_gear);
    
    set_value_select = set->id;
    for(i=0;i!=4;i++) { //更新快捷设置值
        int_to_str(str, set->shortcut[i], 0, 0, NULL);
        strcpy(btnShortcutLabel[i],str);
        lv_btnmatrix_set_map(ui_BtnShortcut, (const char **)btnShortcutMap);
    }
    lv_label_set_text(ui_LabelSetValueName,set->name); //更新参数名

    int_to_str(str, *set->src_value, 0, 0, NULL);
    lv_textarea_set_text(ui_TextSetValue,str);//更新当前值

    lv_obj_clear_flag(ui_PanelSetValue, LV_OBJ_FLAG_HIDDEN);//设置界面进入

}

static void shortcut_event_cb(lv_event_t * e)
{
    lv_obj_t *ta = lv_event_get_target(e);
    uint8_t id = lv_btnmatrix_get_selected_btn(ta);
    *set_value_group[set_value_select].src_value = set_value_group[set_value_select].shortcut[id];
    app_slave_dev_mht.para.run.gun_fan_gear = lv_arc_get_value(ui_ArcGunFan);
    send_write_para_cmd();
    lv_obj_add_flag(ui_PanelSetValue, LV_OBJ_FLAG_HIDDEN);
}

//更新波形
static void wave_refresh(void)
{
    uint8_t index = lv_dropdown_get_selected(ui_DropdownChart);
    wave[has_show_num++] = app_slave_dev_mht.meter[index].value*meter_para_group[index].amp;
    if(has_show_num>=WAVE_POINT_NUM)
        has_show_num = 0;
    lv_chart_refresh(ui_Chart);
}

static void dropdownChart_event_cb(lv_event_t * e)
{
    uint8_t index = lv_dropdown_get_selected(ui_DropdownChart);
    lv_chart_set_range(ui_Chart, LV_CHART_AXIS_PRIMARY_Y, 0, meter_para_group[index].max);
    cursor_refresh();
}
